package com.niiwoo.civet.mobile.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.niiwoo.civet.mobile.vo.request.FeedBackSaveRequestVO;
import com.niiwoo.civet.user.dto.request.FeedBackSaveRequestDTO;
import com.niiwoo.civet.user.enums.FeedBackSaveEunm;
import com.niiwoo.civet.user.service.UserBasicInfoDubboService;
import com.niiwoo.tripod.consumer.util.EmojiFilter;
import com.niiwoo.tripod.provider.exception.BizException;
import com.niiwoo.tripod.web.util.PrincipalContext;
import com.niiwoo.tripod.web.vo.Empty;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.Date;

/**
 * Created by wuke on 2017/10/12
 */
@RestController
@RequestMapping("/setting")
@Api(tags = "设置(李健)", description = "/setting")
public class SettingController {

    @Reference(version = "1.0.0")
    private UserBasicInfoDubboService userBasicInfoDubboService;

    @PostMapping("/feedBackSave")
    @ApiOperation("意见反馈信息保存")
    public Empty feedBackSave(@RequestBody @Valid FeedBackSaveRequestVO requestVO) {
        String userId = PrincipalContext.getUserId();

        FeedBackSaveRequestDTO requestDTO = new FeedBackSaveRequestDTO();
        requestDTO.setUserId(userId);
        requestDTO.setDeviceType(requestVO.getDeviceType());
        requestDTO.setDeviceSystem(requestVO.getDeviceSystem());
        requestDTO.setAppVersion(requestVO.getAppVersion());
        requestDTO.setType(Byte.valueOf(requestVO.getType()));
        requestDTO.setContent(EmojiFilter.filterEmoji(requestVO.getContent()));
        requestDTO.setHandleStatus(FeedBackSaveEunm.UNKNOWN.getValue());
        requestDTO.setAcceptStatus(FeedBackSaveEunm.UNKNOWN.getValue());
        requestDTO.setCreateTime(new Date());
        requestDTO.setUpdateTime(new Date());
        if(!userBasicInfoDubboService.feedBackSave(requestDTO)){
            throw new BizException("USR10024");
        }
        return Empty.getInstance();
    }

}
